<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android," />





  <link rel="alternate" href="/atom.xml" title="Martin's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="在使用Android终端的过程中，有时候如果能够远程控制，会带来很多便利，那么如何实现Android终端远程控制方案呢？">
<meta name="keywords" content="Android">
<meta property="og:type" content="article">
<meta property="og:title" content="Android终端之远程控制">
<meta property="og:url" content="http://martint.oschina.io/2017/10/30/Android终端之远程控制/index.html">
<meta property="og:site_name" content="Martin&#39;s Blog">
<meta property="og:description" content="在使用Android终端的过程中，有时候如果能够远程控制，会带来很多便利，那么如何实现Android终端远程控制方案呢？">
<meta property="og:updated_time" content="2017-11-02T14:00:24.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android终端之远程控制">
<meta name="twitter:description" content="在使用Android终端的过程中，有时候如果能够远程控制，会带来很多便利，那么如何实现Android终端远程控制方案呢？">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://martint.oschina.io/2017/10/30/Android终端之远程控制/"/>





  <title>Android终端之远程控制 | Martin's Blog</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Martin's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">每天进步一点</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://martint.oschina.io/2017/10/30/Android终端之远程控制/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Martin Tang">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Martin's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android终端之远程控制</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-30T11:03:08+08:00">
                2017-10-30
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/技术笔记/" itemprop="url" rel="index">
                    <span itemprop="name">技术笔记</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/10/30/Android终端之远程控制/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2017/10/30/Android终端之远程控制/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>在使用Android终端的过程中，有时候如果能够远程控制，会带来很多便利，那么如何实现Android终端远程控制方案呢？<br><a id="more"></a></p>
<h3 id="在Android终端部署sshd服务"><a href="#在Android终端部署sshd服务" class="headerlink" title="在Android终端部署sshd服务"></a>在Android终端部署sshd服务</h3><p>Android没有sshd服务，但是<a href="https://github.com/augustobott/droidsshd" target="_blank" rel="external"><strong>droidsshd</strong></a>这个开源项目实现了简单的sshd服务。</p>
<p>安装apk后，必须启动一次，才能在<em>/data/data/br.com.bott.droidsshd/files</em>下生成bin目录，bin目录下包含可执行程序<strong>dropbear</strong>，<strong>dropbearkey</strong>， <strong>dropbearmulti</strong>及<strong>scp</strong>，其实最终都是<strong>dropbearmulti</strong>。</p>
<p>如果有的终端不会在launcher上生成droidsshd图标，可以使用命令<strong>am start -n br.com.bott.droidsshd/.DroidSSHd</strong>启动，从而生成bin目录下的可执行程序。</p>
<p>也可直接在以下地址下载<a href="http://7xqemd.dl1.z0.glb.clouddn.com/androidBin/dropbearmulti" target="_blank" rel="external"><strong>dropbearmulti</strong></a>:</p>
<h3 id="启动dropbear"><a href="#启动dropbear" class="headerlink" title="启动dropbear"></a>启动dropbear</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">dropbear -A -N root -C 123456 -p 2222</div></pre></td></tr></table></figure>
<p>或者禁止密码登录，指定public key file，详细的参数解释如下：<br><figure class="highlight shell"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">Options are:</div><div class="line">-A Android Mode, specify a user explicitly</div><div class="line">-N Android Mode, user name</div><div class="line">-C Android Mode, password</div><div class="line">-R Android Mode, public key file (authorized_keys)</div><div class="line">-U Android Mode, UID</div><div class="line">-G Android Mode, GID</div><div class="line">-b bannerfile	Display the contents of bannerfile before user login</div><div class="line">		(default: none)</div><div class="line">-d dsskeyfile	Use dsskeyfile for the dss host key</div><div class="line">		(default: /data/data/br.com.bott.droidsshd/files/etc/dropbear_dss_host_key)</div><div class="line">-r rsakeyfile	Use rsakeyfile for the rsa host key</div><div class="line">		(default: /data/data/br.com.bott.droidsshd/files/etc/dropbear_rsa_host_key)</div><div class="line">-F		Don't fork into background</div><div class="line">-E		Log to stderr rather than syslog</div><div class="line">-w		Disallow root logins</div><div class="line">-s		Disable password logins</div><div class="line">-g		Disable password logins for root</div><div class="line">-p [address:]port</div><div class="line">		Listen on specified tcp port (and optionally address),</div><div class="line">		up to 10 can be specified</div><div class="line">		(default port is 2222 if none specified)</div><div class="line">-P PidFile	Create pid file PidFile</div><div class="line">		(default /data/data/br.com.bott.droidsshd/files/run/dropbear.pid)</div><div class="line">-W &lt;receive_window_buffer&gt; (default 24576, larger may be faster, max 1MB)</div><div class="line">-K &lt;keepalive&gt;  (0 is never, default 0)</div><div class="line">-I &lt;idle_timeout&gt;  (0 is never, default 0)</div></pre></td></tr></table></figure></p>
<p>如果Android终端的ip可以被访问，那么以上2步就可以使其被远程登录，配合droidsshd里的scp或者busybox里的ftp工具，就可以方便地对Android终端做很多事情了。</p>
<p>但是在实际使用中，Android终端往往通过sim卡上网，这个时候，ip地址一般都是不能外部直接访问的，那么这种情况如何解决？</p>
<ol>
<li><p>在Android终端上安装ssh client<br>本来<strong>dropbearmulti</strong>应该也支持ssh client的，但是实际使用上总是报错<em>Unknown own user</em>。<br>直接去github上找个<a href="https://github.com/jackpal/android-command-line-ssh" target="_blank" rel="external">ssh client</a>好了。<br>也可直接下载<a href="http://7xqemd.dl1.z0.glb.clouddn.com/androidBin/ssh" target="_blank" rel="external">ssh</a>和<a href="http://7xqemd.dl1.z0.glb.clouddn.com/androidBin/libssh.so" target="_blank" rel="external">libssh.so</a>。</p>
</li>
<li><p>架设一台云服务器（比如阿里云），Android终端通过ssh tunnel<sup><a href="#ref1">[1]</a></sup>在云服务器上做端口映射，然后我们登录云服务器，通过映射的端口访问Android终端。</p>
</li>
</ol>
<hr>
<p>参考：</p>
<p>[1]. <a id="ref1"><a href="http://blog.csdn.net/wxqee/article/details/49234595" target="_blank" rel="external">SSH Tunnel 一般场景用法</a></a></p>
<p>[2]. <a href="https://blog.0x0f.me/linux/android/586.html" target="_blank" rel="external">安卓命令行配置网络,ssh服务,开机自启动</a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag"># Android</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/06/18/ZSH和oh-my-zsh/" rel="next" title="ZSH和oh-my-zsh">
                <i class="fa fa-chevron-left"></i> ZSH和oh-my-zsh
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/12/19/Tmux使用总结/" rel="prev" title="Tmux使用总结">
                Tmux使用总结 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2017/10/30/Android终端之远程控制/"
           data-title="Android终端之远程控制" data-url="http://martint.oschina.io/2017/10/30/Android终端之远程控制/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Martin Tang" />
          <p class="site-author-name" itemprop="name">Martin Tang</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">33</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">8</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#在Android终端部署sshd服务"><span class="nav-number">1.</span> <span class="nav-text">在Android终端部署sshd服务</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动dropbear"><span class="nav-number">2.</span> <span class="nav-text">启动dropbear</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Martin Tang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"martintang"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  
















  





  

  

  

  

  

  

</body>
</html>
